package com.qiantu.phone.ui.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.hjq.widget.swipelayout.SimpleSwipeListener;
import com.hjq.widget.swipelayout.SwipeLayout;
import com.hjq.widget.swipelayout.adapters.RecyclerSwipeAdapter;
import com.qiantu.api.db.LLDeviceDBManager;
import com.qiantu.api.db.LLRoomDBManager;
import com.qiantu.api.entity.ControlDataAirConditionerBean;
import com.qiantu.api.entity.ControlDataFloorHeatingBean;
import com.qiantu.api.entity.ControlDataFreshAirBean;
import com.qiantu.api.entity.DeviceBean;
import com.qiantu.api.entity.DeviceModeValue;
import com.qiantu.api.entity.LinkageBean;
import com.qiantu.api.entity.WeatherValueBean;
import com.qiantu.api.utils.DeviceInfoParseUtil;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppApplication;
import com.qiantu.phone.bean.WeatherTypeBean;
import com.qiantu.phone.glide.GlideApp;
import com.qiantu.phone.ui.uiutil.DeviceMainType;
import com.qiantu.phone.ui.uiutil.LLDeviceUtil;
import com.qiantu.phone.ui.uiutil.LLSceneLinkageUtil;
import com.qiantu.phone.utils.WeatherConditionTypeParseUtil;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class LinkageConditionAdapter extends RecyclerSwipeAdapter {

    private List<LinkageBean.LinkageCondition> mData;

    public String targetSerialNo;

    public List<LinkageBean.LinkageCondition> getData() {
        return mData;
    }

    public void setData(List<LinkageBean.LinkageCondition> data) {
        this.mData = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.condition_item, parent, false);
        return new ConditionItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        ConditionItemViewHolder vh = (ConditionItemViewHolder) viewHolder;
        LinkageBean.LinkageCondition linkageCondition = mData.get(position);
        String logicTypeStr = "";
        String stateValueStr = "";
        StringBuilder stringBuilder = null;
        vh.tvReverse.setVisibility(View.GONE);
        switch (linkageCondition.getConditionType()) {
            case 1://定时
                if(linkageCondition.isReverse()){
                    vh.tvReverse.setVisibility(View.VISIBLE);
                }else{
                    vh.tvReverse.setVisibility(View.GONE);
                }
                vh.icon.setImageDrawable(AppApplication.getInstance().getThemeDrawable(R.attr.icon_intelligent_condition_timing));
                vh.name.setText(R.string.timing);
                
                String hour = String.format("%02d", linkageCondition.getHour());
                String minute = String.format("%02d", linkageCondition.getMinute());
                
                if(linkageCondition.getTimeTypeId() == 0) {
                    // 普通时间
                    vh.value1.setText(hour + ":" + minute);
                } else if(linkageCondition.getTimeTypeId() == 1) {
                    // 时间段
                    String toHour = String.format("%02d", linkageCondition.getToHour());
                    String toMinute = String.format("%02d", linkageCondition.getToMinute());
                    vh.value1.setText(hour + ":" + minute + " - " + toHour + ":" + toMinute);
                } else if(linkageCondition.getTimeTypeId() == 2) {
                    // 日出日落时间
                    StringBuilder sunriseTime = new StringBuilder();
                    StringBuilder sunsetTime = new StringBuilder();
                    
                    // 处理日出时间
                    int sunriseMinutes = linkageCondition.getMinute();
                    // 根据 sunPositionType 判断是日出还是日落
                    // 1: 日出, 2: 日落
                    if(linkageCondition.getSunTypeId() == 0) {
                        // 日落
                        sunriseTime.append(AppApplication.getInstance().getString(R.string.sunrise));
                    } else {
                        sunriseTime.append(AppApplication.getInstance().getString(R.string.sunset));
                    }
                    
                    // 如果有时间偏移，添加"前"或"后"的说明
                    if(sunriseMinutes != 0) {
                        String sunrisePrefix = sunriseMinutes < 0 ? 
                            AppApplication.getInstance().getString(R.string.when_before) :
                            AppApplication.getInstance().getString(R.string.when_after);
                        
                        // 根据分钟数获取对应的时间文本
                        String timeText;
                        int absMinutes = Math.abs(sunriseMinutes);
                        if (absMinutes == 5) {
                            timeText = sunriseMinutes < 0 ? 
                                AppApplication.getInstance().getString(R.string.when_5_minutes_ago) :
                                AppApplication.getInstance().getString(R.string.when_5_minutes_later);
                        } else if (absMinutes == 10) {
                            timeText = sunriseMinutes < 0 ? 
                                AppApplication.getInstance().getString(R.string.when_10_minutes_ago) :
                                AppApplication.getInstance().getString(R.string.when_10_minutes_later);
                        } else if (absMinutes == 30) {
                            timeText = sunriseMinutes < 0 ? 
                                AppApplication.getInstance().getString(R.string.when_30_minutes_ago) :
                                AppApplication.getInstance().getString(R.string.when_30_minutes_later);
                        } else if (absMinutes == 60) {
                            timeText = sunriseMinutes < 0 ? 
                                AppApplication.getInstance().getString(R.string.when_1_hours_ago) :
                                AppApplication.getInstance().getString(R.string.when_1_hours_later);
                        } else if (absMinutes == 120) {
                            timeText = sunriseMinutes < 0 ? 
                                AppApplication.getInstance().getString(R.string.when_2_hours_ago) :
                                AppApplication.getInstance().getString(R.string.when_2_hours_later);
                        } else {
                            // 其他时间使用格式化字符串
                            timeText = AppApplication.getInstance().getString(
                                sunriseMinutes < 0 ? R.string.when_minutes_ago_holder : R.string.when_minutes_later_holder,
                                absMinutes
                            );
                        }
                        sunriseTime.append(timeText);
                    }
                    
                    // 处理日落时间
                    int sunsetMinutes = linkageCondition.getToMinute();
                    // 使用 toSunPositionType 判断日落时间类型
                    // 1: 日出, 2: 日落
                    if(linkageCondition.getToSunTypeId() == 0) {
                        //日落
                        sunsetTime.append(AppApplication.getInstance().getString(R.string.sunrise));
                    } else {
                        sunsetTime.append(AppApplication.getInstance().getString(R.string.sunset));
                    }
                    
                    // 如果有时间偏移，添加"前"或"后"的说明
                    if(sunsetMinutes != 0) {
                        String sunsetPrefix = sunsetMinutes < 0 ? 
                            AppApplication.getInstance().getString(R.string.when_before) :
                            AppApplication.getInstance().getString(R.string.when_after);
                        
                        // 根据分钟数获取对应的时间文本
                        String timeText;
                        int absMinutes = Math.abs(sunsetMinutes);
                        if (absMinutes == 5) {
                            timeText = sunsetMinutes < 0 ? 
                                AppApplication.getInstance().getString(R.string.when_5_minutes_ago) :
                                AppApplication.getInstance().getString(R.string.when_5_minutes_later);
                        } else if (absMinutes == 10) {
                            timeText = sunsetMinutes < 0 ? 
                                AppApplication.getInstance().getString(R.string.when_10_minutes_ago) :
                                AppApplication.getInstance().getString(R.string.when_10_minutes_later);
                        } else if (absMinutes == 30) {
                            timeText = sunsetMinutes < 0 ? 
                                AppApplication.getInstance().getString(R.string.when_30_minutes_ago) :
                                AppApplication.getInstance().getString(R.string.when_30_minutes_later);
                        } else if (absMinutes == 60) {
                            timeText = sunsetMinutes < 0 ? 
                                AppApplication.getInstance().getString(R.string.when_1_hours_ago) :
                                AppApplication.getInstance().getString(R.string.when_1_hours_later);
                        } else if (absMinutes == 120) {
                            timeText = sunsetMinutes < 0 ? 
                                AppApplication.getInstance().getString(R.string.when_2_hours_ago) :
                                AppApplication.getInstance().getString(R.string.when_2_hours_later);
                        } else {
                            // 其他时间使用格式化字符串
                            timeText = AppApplication.getInstance().getString(
                                sunsetMinutes < 0 ? R.string.when_minutes_ago_holder : R.string.when_minutes_later_holder,
                                absMinutes
                            );
                        }
                        sunsetTime.append(timeText);
                    }
                    
                    // 组合显示日出日落时间
                    vh.value1.setText(sunriseTime + " - " + sunsetTime);
                }
                
                // 使用原有的重复时间处理逻辑
                vh.value2.setText(LLSceneLinkageUtil.getTimingValue(linkageCondition));
                break;
            case 2://环境温度
            case 12://噪音
            case 13://光照度
            case 14://pm2.5
                getEnviromentConditionView(vh,linkageCondition);
                break;
            case 3://环境湿度
                //室内:1、外:2
                vh.icon.setImageDrawable(AppApplication.getInstance().getThemeDrawable(R.attr.icon_intelligent_environment_humidity));
                if (linkageCondition.getAreaType() == 1) {
                    vh.name.setText(R.string.indoor_humidity);
                } else {
                    vh.name.setText(R.string.outdoor_humidity);
                }
                vh.value2.setText(linkageCondition.getBeginValue() + "%~" + linkageCondition.getEndValue() + "%");
                break;
            case 4://环境天气
                vh.name.setText(R.string.weather);
//                try {
//                    JSONArray jsonArray = new JSONArray(linkageCondition.getWeatherKeyValue());
//                    StringBuilder stringBuilder = new StringBuilder();
//                    for (int i = 0; i < jsonArray.length(); i++) {
//                        String name = jsonArray.getJSONObject(i).getString("Name");
//                        stringBuilder.append(name).append("、");
//                    }
//                    vh.value2.setText(stringBuilder.substring(0, stringBuilder.length() - 1));
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
                vh.icon.setImageBitmap(null);
                if(linkageCondition.getWeatherKeyValue() != null){
                    List<WeatherTypeBean> weatherTypeBeans = WeatherConditionTypeParseUtil.parseData(AppApplication.getInstance());
                    stringBuilder = new StringBuilder();
                    for (WeatherValueBean weatherValue : linkageCondition.getWeatherKeyValue()) {
                        out:
                        for (WeatherTypeBean weatherTypeBean : weatherTypeBeans) {
                            for(WeatherValueBean weatherValue1 : weatherTypeBean.getValues()){
                                if (weatherValue1.getValue() == weatherValue.getValue()) {
                                    int imageRes = AppApplication.getInstance().getResourceId(weatherTypeBean.getImage(), "attr");
                                    vh.icon.setImageDrawable(AppApplication.getInstance().getThemeDrawable(imageRes));
                                    break out;
                                }
                            }
                        }
                        int nameRes = AppApplication.getInstance().getResources().getIdentifier(weatherValue.getName(), "string", AppApplication.getInstance().getPackageName());
                        if(nameRes == 0){
                            stringBuilder.append(weatherValue.getName()).append("、");
                        }else{
                            stringBuilder.append(AppApplication.getInstance().getResources().getString(nameRes)).append("、");
                        }
                    }
                    vh.value2.setText(stringBuilder.substring(0, stringBuilder.length() - 1));
                }else{
                    vh.value2.setText("");
                }
                break;
            case 5://环境空气质量
                getAirQualityConditionView(vh,linkageCondition);
                break;
            case 6://环境日出日落
                vh.name.setText(R.string.sunrise_sunset);
                stringBuilder = new StringBuilder();
                switch (linkageCondition.getSunPositionType()) {//1日出、2日落
                    case 1:
                        vh.icon.setImageDrawable(AppApplication.getInstance().getThemeDrawable(R.attr.icon_intelligent_environment_sunrise));
                        stringBuilder.append(AppApplication.getInstance().getString(R.string.sunrise));
                        break;
                    case 2:
                        vh.icon.setImageDrawable(AppApplication.getInstance().getThemeDrawable(R.attr.icon_intelligent_environment_sunset));
                        stringBuilder.append(AppApplication.getInstance().getString(R.string.sunset));
                        break;
                }
                int sunriseSunsetMinute = linkageCondition.getTimeLong() / 1000 / 60;
                if(linkageCondition.getTimeLong() > 0){
                    if(sunriseSunsetMinute / 60 > 0){
                        stringBuilder.append(AppApplication.getInstance().getString(R.string.when_hours_later_holder, sunriseSunsetMinute / 60));
                    }else{
                        stringBuilder.append(AppApplication.getInstance().getString(R.string.when_minutes_later_holder, sunriseSunsetMinute));
                    }
                }else if(linkageCondition.getTimeLong() < 0 ){
                    sunriseSunsetMinute = Math.abs(sunriseSunsetMinute);
                    if(sunriseSunsetMinute / 60 > 0){
                        stringBuilder.append(AppApplication.getInstance().getString(R.string.when_hours_ago_holder, sunriseSunsetMinute / 60));
                    }else{
                        stringBuilder.append(AppApplication.getInstance().getString(R.string.when_minutes_ago_holder, sunriseSunsetMinute));
                    }
                }else{
                    stringBuilder.append(AppApplication.getInstance().getString(R.string.when_time));
                }
                String[] areas = linkageCondition.getAreaName().split(" ");
                String area = "";
                if (areas != null && areas.length > 0) {
                    area = areas[areas.length - 1];
                }
                vh.value1.setText(area + " " + stringBuilder.toString());
                vh.value2.setText(LLSceneLinkageUtil.getTimingValue(linkageCondition));
                break;
            case 7://定位
                vh.name.setText(R.string.location);
                vh.icon.setImageDrawable(AppApplication.getInstance().getThemeDrawable(R.attr.icon_intelligent_environment_location));
                vh.value2.setText(linkageCondition.getBriefing());
                break;
            case 8://设备状态
                String deviceSerialNo = linkageCondition.getDeviceSerialNo();
                DeviceBean device = LLDeviceDBManager.getInstance(AppApplication.getInstance()).get(deviceSerialNo);
                if(device == null){
                    return;
                }
                GlideApp.with(vh.icon)
                        .load(device.getOnImageUrl())
                        .placeholder(vh.icon.getDrawable())
                        .error(vh.icon.getDrawable())
                        .into(vh.icon);
                vh.name.setText(device.getName());
                vh.value1.setText(LLRoomDBManager.getInstance(AppApplication.getInstance()).getFloorRoomName(device.getRoomSerialNo()));
                String stateValue = linkageCondition.getStateValue();
                String stateValueName = null;
                ControlDataAirConditionerBean airConditionerInfo = null;
                ControlDataFreshAirBean freshAirInfo = null;
                ControlDataFloorHeatingBean floorHeatingInfo = null;
                vh.swipeLayout.setSelected(targetSerialNo != null && targetSerialNo.equals(deviceSerialNo));
                switch (linkageCondition.getStateName()){
                    case LLDeviceUtil.POWER:
                        stateValueName = "1".equals(stateValue) ? AppApplication.getInstance().getString(R.string.switch_on) : AppApplication.getInstance().getString(R.string.switch_off);
                        vh.value2.setText(AppApplication.getInstance().getString(R.string.power_status_holder, stateValueName));
                        break;
                    case LLDeviceUtil.STROKE_PERCENTAGE:
                        vh.value2.setText(AppApplication.getInstance().getString(R.string.Binging_StrokePercentage) + " " + linkageCondition.getBeginValue() + "%~" + linkageCondition.getEndValue() + "%");
                        break;
                    case LLDeviceUtil.LIGHT:
                        switch (linkageCondition.getLogicType()){
                            case 1:
                                logicTypeStr = AppApplication.getInstance().getString(R.string.less_than);
                                break;
                            case 2:
                                logicTypeStr = AppApplication.getInstance().getString(R.string.equal_to);
                                break;
                            case 3:
                                logicTypeStr = AppApplication.getInstance().getString(R.string.greater_than);
                                break;
                        }
                        vh.value2.setText(AppApplication.getInstance().getString(R.string.light_status_holder, logicTypeStr, stateValue) + "%");
                        break;
                    case LLDeviceUtil.KELVIN:
                        switch (linkageCondition.getLogicType()){
                            case 1:
                                logicTypeStr = AppApplication.getInstance().getString(R.string.less_than);
                                break;
                            case 2:
                                logicTypeStr = AppApplication.getInstance().getString(R.string.equal_to);
                                break;
                            case 3:
                                logicTypeStr = AppApplication.getInstance().getString(R.string.greater_than);
                                break;
                        }
                        vh.value2.setText(AppApplication.getInstance().getString(R.string.kelvin_status_holder, logicTypeStr, stateValue));
                        break;
                    case LLDeviceUtil.MODE:
                        if(DeviceMainType.AIRCONDITIONER.stringType.equals(device.getType())){
                            airConditionerInfo = DeviceInfoParseUtil.parseData(AppApplication.getInstance(), device.getDeviceType(), ControlDataAirConditionerBean.class);
                            for(DeviceModeValue deviceModeValue : airConditionerInfo.getControlData().getMode()){
                                if(linkageCondition.getStateValue().equals(deviceModeValue.getValue() + "")){
                                    int res = AppApplication.getInstance().getResources().getIdentifier(deviceModeValue.getName(), "string", AppApplication.getInstance().getPackageName());
                                    String value2 = AppApplication.getInstance().getString(res);
                                    vh.value2.setText(AppApplication.getInstance().getString(R.string.Linkage_Device_Mode) + " " + value2);
                                    break;
                                }
                            }
                        }else if(DeviceMainType.FRESHAIR.stringType.equals(device.getType())){
                            freshAirInfo = DeviceInfoParseUtil.parseData(AppApplication.getInstance(), device.getDeviceType(), ControlDataFreshAirBean.class);
                            for(DeviceModeValue deviceModeValue : freshAirInfo.getControlData().getMode()){
                                if(linkageCondition.getStateValue().equals(deviceModeValue.getValue() + "")){
                                    int res = AppApplication.getInstance().getResources().getIdentifier(deviceModeValue.getName(), "string", AppApplication.getInstance().getPackageName());
                                    String value2 = AppApplication.getInstance().getString(res);
                                    vh.value2.setText(AppApplication.getInstance().getString(R.string.Linkage_Device_Mode) + " " + value2);
                                    break;
                                }
                            }
                        }else if(DeviceMainType.FLOORHEATING.stringType.equals(device.getType())){
                            floorHeatingInfo = DeviceInfoParseUtil.parseData(AppApplication.getInstance(), device.getDeviceType(), ControlDataFloorHeatingBean.class);
                            for(DeviceModeValue deviceModeValue : floorHeatingInfo.getControlData().getMode()){
                                if(linkageCondition.getStateValue().equals(deviceModeValue.getValue() + "")){
                                    int res = AppApplication.getInstance().getResources().getIdentifier(deviceModeValue.getName(), "string", AppApplication.getInstance().getPackageName());
                                    String value2 = AppApplication.getInstance().getString(res);
                                    vh.value2.setText(AppApplication.getInstance().getString(R.string.Linkage_Device_Mode) + " " + value2);
                                    break;
                                }
                            }
                        }
                        break;
                    case LLDeviceUtil.WIND_SPEED:
                        if(DeviceMainType.AIRCONDITIONER.stringType.equals(device.getType())){
                            airConditionerInfo = DeviceInfoParseUtil.parseData(AppApplication.getInstance(), device.getDeviceType(), ControlDataAirConditionerBean.class);
                            for(DeviceModeValue deviceModeValue : airConditionerInfo.getControlData().getWindspeed()){
                                if(linkageCondition.getStateValue().equals(deviceModeValue.getValue() + "")){
                                    int res = AppApplication.getInstance().getResources().getIdentifier(deviceModeValue.getName(), "string", AppApplication.getInstance().getPackageName());
                                    String value2 = AppApplication.getInstance().getString(res);
                                    vh.value2.setText(AppApplication.getInstance().getString(R.string.Linkage_Device_WindSpeed) + " " + value2);
                                    break;
                                }
                            }
                        }else if(DeviceMainType.FRESHAIR.stringType.equals(device.getType())){
                            freshAirInfo = DeviceInfoParseUtil.parseData(AppApplication.getInstance(), device.getDeviceType(), ControlDataFreshAirBean.class);
                            for(DeviceModeValue deviceModeValue : freshAirInfo.getControlData().getWindspeed()){
                                if(linkageCondition.getStateValue().equals(deviceModeValue.getValue() + "")){
                                    int res = AppApplication.getInstance().getResources().getIdentifier(deviceModeValue.getName(), "string", AppApplication.getInstance().getPackageName());
                                    String value2 = AppApplication.getInstance().getString(res);
                                    vh.value2.setText(AppApplication.getInstance().getString(R.string.Linkage_Device_WindSpeed) + " " + value2);
                                    break;
                                }
                            }
                        }
                        break;
                    case LLDeviceUtil.WIND_DIRECTION:
                        airConditionerInfo = DeviceInfoParseUtil.parseData(AppApplication.getInstance(), device.getDeviceType(), ControlDataAirConditionerBean.class);
                        for(DeviceModeValue deviceModeValue : airConditionerInfo.getControlData().getWinddirection()){
                            if(linkageCondition.getStateValue().equals(deviceModeValue.getValue() + "")){
                                int res = AppApplication.getInstance().getResources().getIdentifier(deviceModeValue.getName(), "string", AppApplication.getInstance().getPackageName());
                                String value2 = AppApplication.getInstance().getString(res);
                                vh.value2.setText(AppApplication.getInstance().getString(R.string.Linkage_Device_SwingWind) + " " + value2);
                                break;
                            }
                        }
                        break;
                    case LLDeviceUtil.EXHAUST_SPEED:
                        freshAirInfo = DeviceInfoParseUtil.parseData(AppApplication.getInstance(), device.getDeviceType(), ControlDataFreshAirBean.class);
                        for(DeviceModeValue deviceModeValue : freshAirInfo.getControlData().getExhaustspeed()){
                            if(linkageCondition.getStateValue().equals(deviceModeValue.getValue() + "")){
                                int res = AppApplication.getInstance().getResources().getIdentifier(deviceModeValue.getName(), "string", AppApplication.getInstance().getPackageName());
                                String value2 = AppApplication.getInstance().getString(res);
                                vh.value2.setText(AppApplication.getInstance().getString(R.string.Linkage_Device_ExhaustwindSpeed) + " " + value2);
                                break;
                            }
                        }
                        break;
                }
                break;
            case 9://人体感应
            case 10://人体存在感应
            case 16:
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
                getInductionConditionView(vh,linkageCondition);
                break;
        }
        //定时没有区域
        if(linkageCondition.getConditionType() == 7){
            if(linkageCondition.getScopeLong() < 1000){
                vh.value1.setText(linkageCondition.getScopeLong() + "m");
            }else{
                vh.value1.setText(linkageCondition.getScopeLong() / 1000 + "km");
            }
        }else if(linkageCondition.getConditionType() != 6 && linkageCondition.getConditionType() != 9 && linkageCondition.getConditionType() != 10){
            if (!TextUtils.isEmpty(linkageCondition.getAreaName())) {
                if (linkageCondition.getAreaType() == 1) {
                    vh.value1.setText(linkageCondition.getAreaName());
                } else {
                    if(linkageCondition.getAreaName().contains(" ")){
                        String[] areas = linkageCondition.getAreaName().split(" ");
                        if (areas != null && areas.length > 2) {
                            vh.value1.setText(areas[2]);
                        }
                    }else{
                        vh.value1.setText(linkageCondition.getAreaName());
                    }
                }
            }
        }
        vh.swipeLayout.addSwipeListener(new SimpleSwipeListener() {
            @Override
            public void onOpen(SwipeLayout layout) {
                viewHolder.setIsRecyclable(false);
            }

            @Override
            public void onClose(SwipeLayout layout) {
                viewHolder.setIsRecyclable(true);
            }
        });
        vh.ly.setTag(position);
        vh.ly.setOnClickListener(listener);
        vh.deleteImage.setTag(position);
        vh.deleteImage.setOnClickListener(listener);
//        vh.addImage.setTag(position);
//        vh.addImage.setOnClickListener(listener);
        mItemManger.bind(viewHolder.itemView, position);//实现只展现一条列表项的侧滑区域
    }

    private void getInductionConditionView(ConditionItemViewHolder vh, LinkageBean.LinkageCondition linkageCondition) {
        String stateValueStr = "";
        vh.name.setText(linkageCondition.getBriefing());
        GlideApp.with(vh.icon).load(linkageCondition.getImageUrl()).into(vh.icon);
//        vh.icon.setImageDrawable(AppApplication.getInstance().getThemeDrawable(linkageCondition.getImageUrl()));
        switch (linkageCondition.getStateValue()){
            case "1":
                stateValueStr = AppApplication.getInstance().getString(R.string.somebody);
                break;
            case "0":
                stateValueStr = AppApplication.getInstance().getString(R.string.nobody);
                break;
        }
        vh.value1.setText(AppApplication.getInstance().getString(R.string.effective_when_time_holder, stateValueStr));
        vh.value2.setText(stateValueStr);
    }

    private void getAirQualityConditionView(ConditionItemViewHolder vh, LinkageBean.LinkageCondition linkageCondition) {
        //室内:1、外:2
        if (linkageCondition.getAreaType() == 1) {
            vh.name.setText(R.string.indoor_air_quality);
        } else {
            vh.name.setText(R.string.outdoor_air_quality);
        }
        vh.icon.setImageDrawable(AppApplication.getInstance().getThemeDrawable(R.attr.icon_intelligent_environment_pm25));
        switch (linkageCondition.getAriGradeType()) {//1优、2良、3差
            case 1:
                vh.value2.setText(R.string.excellent);
                break;
            case 2:
                vh.value2.setText(R.string.good);
                break;
            case 3:
                vh.value2.setText(R.string.poor);
                break;
        }
    }

    private void getEnviromentConditionView(ConditionItemViewHolder vh, LinkageBean.LinkageCondition linkageCondition) {
        String logicTypeStr = "";
        vh.name.setText(linkageCondition.getBriefing());
        GlideApp.with(vh.icon).load(linkageCondition.getImageUrl()).into(vh.icon);
        switch (linkageCondition.getLogicType()) {
            case 1:
                logicTypeStr = AppApplication.getInstance().getString(R.string.less_than);
                break;
            case 2:
                logicTypeStr = AppApplication.getInstance().getString(R.string.equal_to);
                break;
            case 3:
                logicTypeStr = AppApplication.getInstance().getString(R.string.greater_than);
                break;
        }
        vh.value2.setText(logicTypeStr + linkageCondition.getBeginValue() + LLSceneLinkageUtil.getLinkageUnit(linkageCondition.getConditionType()));
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public long getItemId(int position) {
        return super.getItemId(position);
    }

    @Override
    public int getSwipeLayoutResourceId(int position) {
        return R.id.swipe_layout;
    }

    private final View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = (int) v.getTag();
//            if (v.getId() == R.id.add_image) {
//                Intent intent = new Intent(v.getContext(), AddTaskActivity.class);
//                intent.putExtra("position", position);
//                v.getContext().startActivity(intent);
//                mItemManger.closeItem(position);
//            } else
            if (v.getId() == R.id.delete_image) {
                if (mClickListener != null) {
                    mClickListener.onDelete(position);
                }
            } else if (v.getId() == R.id.ly) {
                if (mItemManger.isOpen(position)) {
                    mItemManger.closeItem(position);
                } else {
                    if (mClickListener != null) {
                        mClickListener.onEdit(position);
                    }
                }
            }
        }
    };

    private class ConditionItemViewHolder extends RecyclerView.ViewHolder {
        public SwipeLayout swipeLayout;
        public LinearLayout seeLayout;
        public ImageView addImage;
        public ImageView deleteImage;
        public ImageView icon;
        public TextView name;
        public TextView tvReverse;
        public TextView value1;
        public TextView value2;
        public View ly;

        public ConditionItemViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            swipeLayout = itemView.findViewById(R.id.swipe_layout);
            seeLayout = itemView.findViewById(R.id.see_layout);
            addImage = itemView.findViewById(R.id.add_image);
            deleteImage = itemView.findViewById(R.id.delete_image);
            icon = itemView.findViewById(R.id.icon);
            name = itemView.findViewById(R.id.name);
            tvReverse = itemView.findViewById(R.id.tv_reverse);
            value1 = itemView.findViewById(R.id.value1);
            value2 = itemView.findViewById(R.id.value2);
            ly = itemView.findViewById(R.id.ly);
        }
    }

    private ClickListener mClickListener;

    public void setClickListener(@Nullable ClickListener listener) {
        mClickListener = listener;
    }

    public interface ClickListener {
        void onDelete(int position);

        void onEdit(int position);
    }
}
